package com.liu.stockmarket.ui.datacenter.ui.main

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.liu.stockmarket.R
import com.liu.stockmarket.StockMarketApplication
import com.liu.stockmarket.databinding.FragmentDataCenterBinding
import com.liu.stockmarket.ui.datacenter.DataCenterViewModel

/**
 * A placeholder fragment containing a simple view.
 */
class PlaceholderFragment : Fragment() {

    private lateinit var dataCenterViewModel: DataCenterViewModel
    private var _binding: FragmentDataCenterBinding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)


        val application = this.requireActivity().application as StockMarketApplication

        dataCenterViewModel = ViewModelProvider(this,DataCenterViewModel.DataCenterViewModelFactory(application.easyMoneyRepository)
        ).get(DataCenterViewModel::class.java).apply {
            setIndex(arguments?.getInt(ARG_SECTION_NUMBER) ?: 1)
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        _binding = FragmentDataCenterBinding.inflate(inflater, container, false)
        val root = binding.root


        binding.list.adapter=object: BaseQuickAdapter<String,BaseViewHolder>(R.layout.item_self,(1..30).map {
                               it.toString()
        }.toMutableList()){
            override fun convert(holder: BaseViewHolder, item: String) {

            }

        }
        return root
    }

    companion object {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        private const val ARG_SECTION_NUMBER = "section_number"

        /**
         * Returns a new instance of this fragment for the given section
         * number.
         */
        @JvmStatic
        fun newInstance(sectionNumber: Int): PlaceholderFragment {
            return PlaceholderFragment().apply {
                arguments = Bundle().apply {
                    putInt(ARG_SECTION_NUMBER, sectionNumber)
                }
            }
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}